function newAjax()
{
	var xmlHttp;
	
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
	else
	{
		$.alert("Ajax error");
		xmlHttp = null;
	}
	
	return xmlHttp;
}
//动态显示POST
function Ajax_show(block,purl,pdata)
{
	if(purl!=''){
		var xmlHttp = newAjax();
		var url = purl;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.onreadystatechange = function() 
		{
			if(xmlHttp.readyState == 4)
			{
				var result = xmlHttp.responseText;
				if(document.getElementById(block)){
					document.getElementById(block).innerHTML = result;
                    if(block == 'scr')
                    {
                        //$('#scr').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
                    }
				}
				else{
					if(purl.indexOf('/addcomment/')>-1){//发表新闻评论
						var nodeval=result.split('::');
						var errmsg = nodeval[0];
						var newsid = nodeval[1];
						if( errmsg=='success' ) {
                            if(nodeval[2])
                            {
                                $_CNC_COMMON.creditShow(nodeval[2], nodeval[3]);
                            }
                            else
                            {
                                $.alert('发布成功！');
                            }
							loadnewscomment(newsid,1);
						}
						nowsay = true;
					}
					if(purl.indexOf('/showcollect/')>-1){//显示收藏

                        $.overlay();
						var nodeval=result.split('::');
						var errmsg = nodeval[0];
						var newsid = nodeval[1];
						if(!cookie.get('voguebbsuid')&&cookie.get('voguebbsuid')!=='deleted') {
							//弹出登陆框
							$('#loginBoxId').show();
                            //焦点绑到userNameId上
                            setTimeout("$('#userNameId').focus()", 1);
                            $(".login-title").html('你需要先登录才能继续本操作');
                            $('#loginBoxId').bind('keyup', function(event)
                            {
                               if(event.keyCode=="13")
                               {
                                   $('#loginBtnId').click();
                               }
                            });
						}
						else if( errmsg=='show' || errmsg == 'login') {
							//显示收藏
							var self=$('#collectkey'),pos=self.offset();
							/*
							$('#shareFloatBox').css({
								top:pos.top,
								left:pos.left+self.width()+5
							});
                            */
                            $.box('close');
                            $.overlay();
                            $('#shareFloatBox').center();
							$('#shareFloatBox').show();
						}
						else {
							var self=$('#collectkey'),pos=self.offset();
							
                            /*
							$('#shareOverBox').css({
								top:pos.top,
								left:pos.left+self.width()+5
							});
                            */
                            /*
							$('#shareOverBox').show();
                            */
                            $.box('close');
							//关闭收藏
							$('#shareFloatBox').hide();

                            var string = $_CNC_COMMON.creditReturn('collect');
                            $.alert(string.content);
						}
						nowsay = true;
					}
					if(purl.indexOf('/addcollect/')>-1){//提交收藏
						var nodeval=result.split('::');
						var errmsg = nodeval[0];
						var newsid = nodeval[1];
						if( errmsg=='login' ) {
							//弹出登陆框
							$('#loginBoxId').show();
                            setTimeout("$('#userNameId').focus()", 1);
                            $(".login-title").html('你需要先登录才能继续本操作');
                            $('#loginBoxId').bind('keyup', function(event)
                            {
                               if(event.keyCode=="13")
                               {
                                   $('#loginBtnId').click();
                               }
                            });
							//关闭收藏
                            $.box('close');
							$('#shareFloatBox').hide();
						}
						else {
							//成功收藏
							var self=$('#collectkey'),pos=self.offset();
							
                            /*
							$('#shareSuccessBox').css({
								top:pos.top,
								left:pos.left+self.width()+5
							});
                            */
                            $.overlay();
                            //关闭收藏
							$('#shareFloatBox').hide();

                            //$('#shareSuccessBox').center();
							//$('#shareSuccessBox').show();

                            if(nodeval[2])
                            {
                                $_CNC_COMMON.creditShow(nodeval[2], nodeval[3]);
                            }
                            else
                            {
                                $.alert('收藏成功！');
                            }
							
						}
					}
				}
			}
		}
		xmlHttp.send(pdata); 
	}
}
//动态显示GET
function Ajax_show1(block,purl)
{
	if(purl!=''){
		var xmlHttp = newAjax();
		var url = purl;
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function() 
		{
			if(xmlHttp.readyState == 4)
			{
				var result = xmlHttp.responseText;
				if(document.getElementById(block)){
					document.getElementById(block).innerHTML = result;
				}
			}
		}
		xmlHttp.send(null);
	}
}
//重复提交检查
var nowsay = true;
function loadnewscomment(nid,pg)
{
	var param = '';
	Ajax_show('commentsBox','/front_ajax/comment/'+nid+'/'+pg,param);
}
function addnewscomment(nid,cid,msg)
{
    $.alert('评论发布中...');
    //$.tip({str:'灰色背景',background: '#ccc'});
	if( nowsay ) {
		nowsay = false;
		var newmsg = msg.replace("+", "::or::");
	 	newmsg = newmsg.replace("&", "::and::");
		var param = 'msg='+newmsg;
		Ajax_show('none','/front_ajax/addcomment/'+nid+'/'+cid,param);
	}
	else {
		$.alert('不能重复提交！');
	}
}
function replycomment(nid,cid,uname)
{
	document.getElementById('reply_cid').value = cid;
	document.getElementById('commentTextarea').value = '回复 '+uname+' 的留言：';
	document.getElementById('commentTextarea').focus();
}

function showcollect(nid)
{
	if( nowsay ) {
        showcollect_state = 2;
		nowsay = false;
		var param = '';
		Ajax_show('none','/front_ajax/showcollect/'+nid,param);
	}
	else {
		$.alert('不能重复提交！');
	}
}
function addcollect(nid,msg)
{
	var newmsg = msg.replace("+", "::or::");
 	newmsg = newmsg.replace("&", "::and::");
	var param = 'msg='+newmsg;
	Ajax_show('none','/front_ajax/addcollect/'+nid,param);
}
function viewnews(nid)
{
	var param = '';
	Ajax_show('none','/front_ajax/viewnews/'+nid+'?'+Math.random(),param);
}
function loadcharshow(syear,skey,ckey,keychar)
{
	var param = '';
	Ajax_show('scr','/front_ajax/getcharshow/'+syear+'/'+skey+'/'+ckey+'/'+keychar+'?'+Math.random(),param);
    

    //add by yubin
    $('.tted').removeClass('tted');
    $('.show_' + keychar).addClass('tted');
}
